package com.jsoft.pds.view.util;

import java.io.Serializable;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.faces.context.FacesContext;

public class BundleResource implements Serializable{

	private static final long serialVersionUID = 94569439859484681L;
	
	private static final String GENERAL = "ApplicationResources-general";
	private static final String SCREEN = "ApplicationResources-screen";
	
	private ResourceBundle getBundle(String baseName) {
		return ResourceBundle.getBundle(baseName, FacesContext.getCurrentInstance().getViewRoot().getLocale());
	}
	
	public String getAppText(String key){
		return getResourcesBundle(GENERAL, key);
	}
	
	public String getSrcText(String key){
		return getResourcesBundle(SCREEN, key);
	}

	private String getResourcesBundle(String baseName, String key){
		try{
			return getBundle(baseName).getString(key);
		}catch(MissingResourceException mr){
			return "??" + key;
		}catch (Exception e) {
			return "??" + key + "??";
		}
	}
}
